<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';
require_once './include/advisory_db.php';
//user type
$utype   = ($_SESSION[usertype]=='recruiter')?1:0;



//print_r($_SESSION);
if(!empty($_POST)&&$_POST[type]=='private'){
    $title      = htmlspecialchars(trim($_POST[title]));
	$description= htmlspecialchars(trim($_POST[description]));
	$skypeid    = htmlspecialchars(trim($_POST[skypeid]));
	$date       = htmlspecialchars(trim($_POST['date']));
	$email      = htmlspecialchars(trim($_POST['email']));
	$fullname   = htmlspecialchars(trim($_POST['fullname']));
	$fromhour   = htmlspecialchars(trim($_POST[fromhour]));
	$frommin    = htmlspecialchars(trim($_POST[frommin]));
	$tohour     = htmlspecialchars(trim($_POST[tohour]));
	$tomin      = htmlspecialchars(trim($_POST[tomin]));
	$timezone   = htmlspecialchars(trim($_POST[timezone]));
	$spoken     = htmlspecialchars(trim($_POST[spoken]));
	$pri        = @implode(",",$_POST[pri]);
	$active     = htmlspecialchars(trim($_POST[active]));

	$sql_pri = "SELECT * FROM pa_skypechat WHERE `sp_utype`='".$utype."' AND  `sp_uid`='".$_SESSION[uid]."' AND `sp_chattype` = '0'  ";
	$pri_arr = $DB->fetch_one_array($sql_pri);
	if(empty($pri_arr)){
		$sql = "INSERT INTO `pa_skypechat` (  `sp_uid` , `sp_uname` , `sp_fullname` , `sp_uemail` , `sp_utype` , `sp_date` , `sp_timezone` , `sp_starttime` , `sp_endtime` , `sp_topic`,`sp_description` , `sp_name` , `sp_language` , `sp_selectpage` , `sp_chattype` , `sp_skype` , `sp_color` , `sp_top3` , `sp_status` )
	    VALUES ( '".$_SESSION[uid]."', '".$_SESSION[uname]."', '".$fullname."', '".$email."','".$utype."', '".$date."', '".$timezone."', '".$fromhour.$frommin."', '".$tohour.$tomin."', '".$title."','".$description."', '', '".$spoken."', '".$pri."', '0', '".$skypeid."', '', '', '".$active."') ";

       $DB->query($sql);
	}else{
	    $sql = "UPDATE `pa_skypechat` SET  `sp_fullname`='".$fullname."',`sp_uemail`='".$email."',`sp_utype`='".$utype."',`sp_date`='".$date."',`sp_timezone`='".$timezone."',`sp_starttime`='".$fromhour.$frommin."',`sp_endtime`='".$tohour.$tomin."',`sp_topic`='".$title."',`sp_description`='".$description."',`sp_language`='".$spoken."',`sp_selectpage`='".$pri."',`sp_skype`='".$skypeid."',`sp_status`='".$active."' WHERE `sp_utype`='".$utype."' AND  `sp_uid`='".$_SESSION[uid]."' AND `sp_chattype` = '0' ";
	    $DB->query($sql);
	}

}

if(!empty($_POST)&&$_POST[type]=='public'){
    $title      = htmlspecialchars(trim($_POST[title]));
	$description= htmlspecialchars(trim($_POST[description]));
	$skypeid    = htmlspecialchars(trim($_POST[skypeid]));
	$date       = htmlspecialchars(trim($_POST['date']));
	$email      = htmlspecialchars(trim($_POST['email']));
	$fullname   = htmlspecialchars(trim($_POST['fullname']));
	$fromhour   = htmlspecialchars(trim($_POST[fromhour]));
	$frommin    = htmlspecialchars(trim($_POST[frommin]));
	$tohour     = htmlspecialchars(trim($_POST[tohour]));
	$tomin      = htmlspecialchars(trim($_POST[tomin]));
	$timezone   = htmlspecialchars(trim($_POST[timezone]));
	$spoken     = htmlspecialchars(trim($_POST[spoken]));
	$pub        = @implode(",",$_POST[pub]);
	$active     = htmlspecialchars(trim($_POST[active]));
	$color      = htmlspecialchars(trim($_POST[color]));

	$sql_pub = "SELECT * FROM pa_skypechat WHERE `sp_utype`='".$utype."' AND  `sp_uid`='".$_SESSION[uid]."' AND `sp_chattype` = '1'  ";
	$pub_arr = $DB->fetch_one_array($sql_pub);
	if(empty($pub_arr)){
		$sql = "INSERT INTO `pa_skypechat` (  `sp_uid` , `sp_uname` , `sp_fullname` , `sp_uemail` , `sp_utype` , `sp_date` , `sp_timezone` , `sp_starttime` , `sp_endtime` , `sp_topic`,`sp_description` , `sp_name` , `sp_language` , `sp_selectpage` , `sp_chattype` , `sp_skype` , `sp_color` , `sp_top3` , `sp_status` )
	    VALUES ( '".$_SESSION[uid]."', '".$_SESSION[uname]."', '".$fullname."', '".$email."','".$utype."', '".$date."', '".$timezone."', '".$fromhour.$frommin."', '".$tohour.$tomin."', '".$title."','".$description."', '', '".$spoken."', '".$pub."', '1', '".$skypeid."', '".$color."', '', '".$active."') ";
       $DB->query($sql);
	}else{
	    $sql = "UPDATE `pa_skypechat` SET  `sp_fullname`='".$fullname."',`sp_uemail`='".$email."',`sp_utype`='".$utype."',`sp_date`='".$date."',`sp_timezone`='".$timezone."',`sp_starttime`='".$fromhour.$frommin."',`sp_endtime`='".$tohour.$tomin."',`sp_topic`='".$title."',`sp_description`='".$description."',`sp_language`='".$spoken."',`sp_selectpage`='".$pub."',`sp_skype`='".$skypeid."',`sp_status`='".$active."',`sp_color`='".$color."'  WHERE `sp_utype`='".$utype."' AND  `sp_uid`='".$_SESSION[uid]."' AND `sp_chattype` = '1' ";
	    $DB->query($sql);
	}

}


$sql_pri = "SELECT * FROM pa_skypechat WHERE `sp_utype`='".$utype."' AND  `sp_uid`='".$_SESSION[uid]."' AND `sp_chattype` = '0'  ";
$pri_arr = $DB->fetch_one_array($sql_pri);
if(!empty($pri_arr)){
   $pri_arr[fromhour] = @substr($pri_arr[sp_starttime],0,2);$pri_arr[frommin] = @substr($pri_arr[sp_starttime],2,2);
   $pri_arr[tohour] = @substr($pri_arr[sp_endtime],0,2);$pri_arr[tomin] = @substr($pri_arr[sp_endtime],2,2);
   $pri_arr[page1] = (@ereg('1',$pri_arr['sp_selectpage']))?1:0;
   $pri_arr[page2] = (@ereg('2',$pri_arr['sp_selectpage']))?1:0;
   $pri_arr[page3] = (@ereg('3',$pri_arr['sp_selectpage']))?1:0;
   $pri_arr[page4] = (@ereg('4',$pri_arr['sp_selectpage']))?1:0;
   $smarty->assign('pri', $pri_arr);
   $smarty->assign('pri_action',"edit");
}
if(empty($pri_arr)) $smarty->assign("empty1",'1');

$sql_pub = "SELECT * FROM pa_skypechat WHERE `sp_utype`='".$utype."' AND  `sp_uid`='".$_SESSION[uid]."' AND `sp_chattype` = '1'  ";
$pub_arr = $DB->fetch_one_array($sql_pub);
//print_r($pub_arr);
if(!empty($pub_arr)){
	//print_r($pub_arr);
   $pub_arr[fromhour] = @substr($pub_arr[sp_starttime ],0,2);$pub_arr[frommin] = @substr($pub_arr[sp_starttime],2,2);
   $pub_arr[tohour] = @substr($pub_arr[sp_endtime],0,2);$pub_arr[tomin] = @substr($pub_arr[sp_endtime],2,2);
   $pub_arr[page1] = (@ereg('1',$pub_arr['sp_selectpage']))?1:0;
   $pub_arr[page2] = (@ereg('2',$pub_arr['sp_selectpage']))?1:0;
   $pub_arr[page3] = (@ereg('3',$pub_arr['sp_selectpage']))?1:0;
   $pub_arr[page4] = (@ereg('4',$pub_arr['sp_selectpage']))?1:0;
   $pub_arr[color] = $pub_arr['sp_color'];
   $smarty->assign('pub', $pub_arr);
   $smarty->assign('pub_action',"edit");
}
if(empty($pub_arr)) $smarty->assign("empty2",'1');



$smarty->assign('colors',array('1'=>'<img src="images/smallblock1.gif" border="0" width="10" style="margin:0;padding:0" />',
								'2'=>'<img src="images/smallblock2.gif" border="0" width="10" style="margin:0;padding:0" />',
								'3'=>'<img src="images/smallblock3.gif" border="0" width="10" style="margin:0;padding:0" />',
								'4'=>'<img src="images/smallblock4.gif" border="0" width="10" style="margin:0;padding:0" />'));
$smarty->assign('hours',$hours);
$smarty->assign('mins',$mins);

$smarty->compile_check = true;

$smarty->display('header.tpl');
$smarty->display('allleft.tpl');
$smarty->display('mychats.tpl');
$smarty->display('footer.tpl');


?>